/**
 * Created by kevin on 2017/01/08.
 *
 * page base
 */


var eosi = window.eosi || {};
this.eosi.website = this.eosi.website || {};

(function (window) {

    function VideoPlayer() {
        this.Container_constructor();
        this.init();
    }

    var p = createjs.extend(VideoPlayer, createjs.Container);
    p.className = "VideoPlayer";
    p.loader
    p.resItems=[];
    p.play_id=null;
    p.action;
    p.end_time;

    p.init = function () {
        this.loader = new createjs.LoadQueue(true);
        this.loader.on("fileload", this.onLoaded, this);
        this.loader.on("complete",this.loadComplete , this);
        this.loader.on("progress",this.onProgress, this);
        this.loader.loadManifest({src: BASE_PATH+"static/VideoManif.json?v="+version, callback: "VideoManifGrid", type: "manifest"}, true, "./");
    }
    p.loadComplete=function(){
        loadCoreRes();
        if(Video.html_play_src){
            this.src_read_play(Video.html_play_src)
        }else{
            this.autoplay();
        }
    },
    p.autoplay=function(){
        for(var i = 0 ;i<this.resItems.length;i++){
            var dm=this.resItems[i]
            if(dm.type == "manifest"){
                return;
            }
            if(dm.autoplay){
                this.read_play(dm);//
                break;
            }
        }
    },
    p.onLoaded=function(evt){
        var item = evt.item;
        this.resItems.push(item);
    },
    p.onProgress=function(evt){
        onProgress(evt,0,Video_RES_SIZE_PER);
    },
    p.play = function(src){
        var idRef = "container";
        var lParent = document.getElementById(idRef);
        if (!lParent) {
            var lMesg = "没有元素 [" + idRef + "] ";
            alert(lMesg);
            return null;
        }
        var video = document.getElementById("video")
        video.setAttribute("src",src);
        var viceoHolder = document.getElementById("videobox");
        viceoHolder.style.display = 'block';
    },
    
    /*
    **loading完 播放
    */
    p.read_play=function(dm){
        //先把播放结束回调准备好
        if(dm.action){
            this.action=dm.action;
        }
        if(dm.end_time){
            this.end_time=dm.end_time; 
        }
        this.play_id=dm.id;
        this.play(this.loader.getResult(this.play_id).src);
    },

    /*
    **不loading 直接播放  -----针对首次 html播放 不需要设置属性回调 特殊情况 这个方法不复用
    */
    p.src_read_play=function(src){
        alert(src)
        this.play(src);
    }

    /*
    ** 以下是响应点击播放
    */
    p.click_play_read=function(config){
        if(config.type=="name"){
            this.type_name(config.pop)
        }else if(config.type=="src"){
            this.type_src(config.pop)
        }
    }

    //点击
    p.type_name=function(config){
        if(config.name){
            for(var i = 0 ;i<this.resItems.length;i++){
                var dm=this.resItems[i]
                if(dm.name=config.name){
                    this.read_play(dm);//
                    break;
                }
            }
        }
    }

    //点击
    p.type_src=function(config){
        if(config.action){
            this.action=config.action;
        }
        if(config.end_time){
            this.end_time=config.end_time; 
        }
        this.play_id=config.id;
        this.play(config.src);
    }
    // add MyApp to myNameSpace
    window.eosi.website.VideoPlayer = createjs.promote(VideoPlayer, "Container");
//}());
}(window));





